﻿Replication for: "Bayesian Modeling for Overdispersed Event-Count Time Series" (Kentaro Fukumoto, Andreas Beger, and Will H. Moore), Behaviormetrika, forthcoming. 

* Description: Social scientists are frequently interested in event-count time-series data. One of the state-of-the-art methods, the Poisson exponentially weighted moving average (P-EWMA) model, leads to incorrect inference in the presence of omitted variables even if they are not confounding. To tackle this problem, this paper proposes a negative binomial integrated error [NB-I(1)] model, which can be estimated via Markov Chain Monte Carlo methods. Simulations show that when the data are generated by a P-EWMA model, but an non-confounding covariate is omitted at the stage of estimation, the P-EWMA model's credible interval is optimistically too narrow to contain the true value at the nominal level, whereas the NB-I(1) model does not suffer this problem. To explore the models' performance, we replicate a study on an annual count of militarized interstate disputes.

* Programs: R (versions 3.5.3 and 3.6.1)
Note that we use version 3.5.3 except for step3_6_figure-S14.R and step4_5_table-S6.R, for which we use version 3.6.1.

* Additional programs required: N/A* Process of Replication: 
- Simulation(0) Set the "MC" directory as the working directory.(1) Implement either of the two options below.
[Hard Option](1-1) Run step1_1_do.MC.r to conduct Monte Carlo simulation. It takes DAYS. For computational reasons, sometimes a computer clashes. In that case, we recommend restarting the simulation from where it stops, preferably by using another computer, as we did. Note that there are seven setups, each of which is between "source("baseline.r")" and "source("MC.background.gamma.r")" and has its own random seed.(1-2) Run step1_2_extract.delta.r to extract deltas.
(1-3) Run step1_3_read.all.new.r to read the results.
[Easy Option]Simply do load("results.Rdata") to skip the hard option.(2) Run step2_make.figure.baseline.r to make Figures 1-3.(3) Run step3_read.baseline.pewma.old.pi1.r to make Figures S.4 and S.5.(4) Run step4_make.figure.final.r to make Figures S.6 through S.11.- Application(0) Set the "brandtetal2000" directory as the working directory.
(1) Run step1_make_mid_data.R to make mid_data.rds in the "data" subdirectory.
(2) Run step2_tables-S1-through-S3.R to replicate the original results and make Tables S.1 through S.3 in the "output/tables" subdirectory.
(3) Main analysis
(3-1) Run step3_1_run-stan.R to conduct MCMC for main analysis. It takes hours. You may skip this step because the output file, workspace-dump.rda, is contained in the "output" subdirectory.
(3-2) Run step3_2_figure-4.R to make Figure 4 in the "output/figures" subdirectory.
(3-3) Run step3_3_figure-5.R to make Figures 5 and S.13 in the "output/figures" subdirectory as well as Table 1 in the "output/tables" subdirectory..
(3-4) Run step3_4_run-stan-nbi1-null.R to conduct MCMC for Figure S.3. You may skip this step because the output file, nbi1_null_fit.rds, is contained in the "output/samples" subdirectory.
(3-5) Run step3_5_figure-S3.R to make Figure S.3 in the "output/figures" subdirectory.
(3-6) Run step3_6_figure-S14.R to make Figure S.14 in the "output/figures" subdirectory.
(3-7) Run step3_7_mle.R to make Table S.4 in the "output/figures" subdirectory and Figure S.15 in the "output/figures" subdirectory.
(4) Alternative specifications
(4-1) Run step4_1_additional-models.R to conduct MCMC for alternative specifications. It takes almost a day. You may skip this step because the output file, workspace-dump-additional-models.rda, is contained in the "output" subdirectory.
(4-2) Run step4_2_run-stan-noCR2.R to conduct MCMC for Figure S.12 and make Figure S.12. You may skip this MCMC because the output file, pewma_fit_noCR2.rds, is contained in the "output/samples" subdirectory.
(4-3) Run step4_3_figure-S16.R to make Figure S.16.
(4-4) Run step4_4_table-S5.R to make Table S.5.
(4-5) Run step4_5_table-S6.R to make Table S.6.
(5) Run step5_figures-S1-and-S2.R to make Figures S.1 and S.2.
* Most Recent Date of Successful Replication: November 21, 2019